package magis;

import edu.byu.intex2.data.Controller;
import edu.byu.intex2.data.bo.PhysicalCar;

/**
 * Handles the creation of a new sale line
 * @author Brady
 */
public class ViewWarranties extends javax.swing.JFrame {

    private PhysicalCar pc;

    // jtableModel so that we can fire off changes when saleLine is created.
    WarrantyTableDataModel warrantyTableDataModel = null;

//    SaleItemsTableDataModel saleItemsTableModel = null;

    /** Creates new form AddSaleLine */
    public ViewWarranties(PhysicalCar pc) {
        initComponents();
        Controller.getInstance().center(this);

        this.pc = pc;

        // Set Up Table Model
        setUpTableModel();

        // Assign the labels of the columns
        setColumnLabels();

//        this.saleItemsTableModel = sitdb;
    }

    /** Assign the labels of the columns */
    private void setColumnLabels() {
        warranties_tbl.getColumnModel().getColumn(0).setHeaderValue("Miles");
        warranties_tbl.getColumnModel().getColumn(1).setHeaderValue("Months");
        warranties_tbl.getColumnModel().getColumn(2).setHeaderValue("Type");
        warranties_tbl.getTableHeader().resizeAndRepaint();
    }

    /** Set Up Table Model */
    private void setUpTableModel(){
        // Instantiate saleLinesTableDataModel
        warrantyTableDataModel = new WarrantyTableDataModel(pc);

        // Set the JTable model to saleLinesTableDataModel
        warranties_tbl.setModel(warrantyTableDataModel);

        // Add listener to saleLinesTableDataModel
        warrantyTableDataModel.addTableModelListener(warranties_tbl);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        viewWarrantiesGroup = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        warranties_tbl = new javax.swing.JTable();
        bottomMenu_pnl = new javax.swing.JPanel();
        cancel_btn = new javax.swing.JButton();
        addWarranty_btn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        viewWarrantiesGroup.setBorder(javax.swing.BorderFactory.createTitledBorder("View Warranties"));

        warranties_tbl.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(warranties_tbl);

        javax.swing.GroupLayout viewWarrantiesGroupLayout = new javax.swing.GroupLayout(viewWarrantiesGroup);
        viewWarrantiesGroup.setLayout(viewWarrantiesGroupLayout);
        viewWarrantiesGroupLayout.setHorizontalGroup(
            viewWarrantiesGroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(viewWarrantiesGroupLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 385, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        viewWarrantiesGroupLayout.setVerticalGroup(
            viewWarrantiesGroupLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(viewWarrantiesGroupLayout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        getContentPane().add(viewWarrantiesGroup, java.awt.BorderLayout.CENTER);

        cancel_btn.setFont(new java.awt.Font("Tahoma", 0, 8));
        cancel_btn.setText("Cancel");
        cancel_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancel_btnActionPerformed(evt);
            }
        });
        bottomMenu_pnl.add(cancel_btn);

        addWarranty_btn.setFont(new java.awt.Font("Tahoma", 0, 8)); // NOI18N
        addWarranty_btn.setText("Add Warranty");
        addWarranty_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addWarranty_btnActionPerformed(evt);
            }
        });
        bottomMenu_pnl.add(addWarranty_btn);

        getContentPane().add(bottomMenu_pnl, java.awt.BorderLayout.SOUTH);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cancel_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancel_btnActionPerformed
        this.dispose(); // Close Window
    }//GEN-LAST:event_cancel_btnActionPerformed

    private void addWarranty_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addWarranty_btnActionPerformed
        new SelectWarranty(pc, warrantyTableDataModel).setVisible(true);
}//GEN-LAST:event_addWarranty_btnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                //new AddSaleLine(Model.getInstance().getSale(), setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addWarranty_btn;
    private javax.swing.JPanel bottomMenu_pnl;
    private javax.swing.JButton cancel_btn;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel viewWarrantiesGroup;
    private javax.swing.JTable warranties_tbl;
    // End of variables declaration//GEN-END:variables
}
